﻿using Coolzon.UI.Core;
using Coolzon.UI.Core.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Visifire.Charts;
using Visifire.Commons;

namespace Coolzon.UI.Charts.Widgets
{
    /// <summary>
    /// Interaction logic for DataChartPie.xaml
    /// </summary>
    [XPartIcon("pack://application:,,,/CPPEI.Coolzon.UI.DataPartLib;component/Images/PartIcons/饼图.png")]
    [XPart("ChartPie", "饼图")]
    [System.ComponentModel.DisplayName("饼图")]
    public partial class DataChartPie : DataChartBase
    {
        #region properties
        private double _startAngle = 0;
        /// <summary>
        /// 0代表3点方向，顺时针计算
        /// </summary>
        [Category("其他")]
        [DisplayName("起始绘制角度")]
        [Description("XStartAngle")]
        ////[Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Appearance, "StartAngle", "起始绘制角度", false)]
        public double StartAngle
        {
            get
            {
                return _startAngle;
            }
            set
            {
                _startAngle = value;
                ////Refresh();
            }
        }
        #endregion

        public DataChartPie()
        {
            InitializeComponent();

            DataPointLabelEnabled = true;
            _startAngle = 0;
            PlotAreaBevel = true;
        }

        protected override Chart GetChart()
        {
            return _ctlChart;
        }

        protected override RenderAs GetRender(string dataSeriesId)
        {
            return RenderAs.Pie;
        }

        protected override void ResolveVisifireDataSeries(DataSeries dataSeries)
        {
            dataSeries.StartAngle = _startAngle;
            base.ResolveVisifireDataSeries(dataSeries);
        }

        protected override void ApplyChartColorPlate()
        {
            if (ColorPlate == null)
                return;

            if (_ctlChart.Series != null && _ctlChart.Series.Count > 0)
            {
                if (_ctlChart.Series[0].DataPoints != null)
                {
                    for (int i = 0; i < _ctlChart.Series[0].DataPoints.Count; i++)
                    {
                        _ctlChart.Series[0].DataPoints[i].Color = ColorPlate[i];
                    }
                }
            }
        }

        /// <summary>
        /// 处理数据，每个图表可能有自己相关的数据
        /// </summary>
        /// <param name="dataResult"></param>
        /// <returns></returns>
        protected override List<Coolzon.Web.Models.DataSeries> ResolveDataResult(Coolzon.Web.Models.DataResult dataResult)
        {
            List<Coolzon.Web.Models.DataSeries> seriesList = new List<Web.Models.DataSeries>();
            if(dataResult.DataSeries.Count > 0)
            {
                seriesList.Add(dataResult.DataSeries[0]);
            }
            return seriesList;
        }
    }
}
